from django.test import TestCase

# 使用itsdangerous模块中的TimedJSONWebSignatureSerializer可以对数据进行签名加密和解密。
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadData

# Create your tests here.


# if __name__ == '__main__':
#     # 署名加密
#     req_dict = {
#             'openid': 'KDKKD91929kDKIDIDLL9193'
#         }
#
#     serializer = Serializer(secret_key='handsome', expires_in=300)
#
#     res = serializer.dumps(req_dict)
#
#     # bytes -> str
#     # 加密结果
#     res = res.decode()
#     print(res)


if __name__ == '__main__':
    # 解密
    req_data = 'eyJpYXQiOjE1NTQ1NTQwODIsImV4cCI6MTU1NDU1NDM4MiwiYWxnIjoiSFM1MTIifQ.eyJvcGVuaWQiOiJLREtLRDkxOTI5a0RLSURJRExMOTE5MyJ9.5LkXD6ey5052JP_OANaCGCLjLkang2-QSqhcumoqoqOVuJVTqpxExuWaOMZCPd2fq_A0ugnS88LH9jFHpg0_VQ'


    # 加密的秘钥
    serializer = Serializer(secret_key="handsome")

    try:
        res = serializer.loads(req_data)
    except BadData:
        print("解密失败")
    else:
        print(res)
